//
//  WPTreatmentHeaderFooterView.m
//  wobingwoyi
//
//  Created by WGP on 2016/12/1.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPTreatmentHeaderFooterView.h"

@interface WPTreatmentHeaderFooterView ()

@property(nonatomic,strong)UIView *topView;
@property(nonatomic,strong)UIView *bottomView;
@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIImageView *lineImageView;

@property(nonatomic,strong)UIButton *tipBtn;

@end
@implementation WPTreatmentHeaderFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        [self topView];
        [self bottomView];
        [self iconView];
        [self titleLabel];
        [self lineImageView];
        [self timeLabel];
        
        UIImageView *topLine = [UIImageView lineImageView];
        UIImageView *bottomLine = [UIImageView lineImageView];
        [self.contentView addSubview:topLine];
        [self.contentView addSubview:bottomLine];
        
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
            make.centerY.equalTo(self.contentView);
        }];
        
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
        
        UIButton *tipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.tipBtn = tipBtn;
        [tipBtn setImage:[UIImage imageNamed:@"mandatory_star"] forState:UIControlStateNormal];
        [tipBtn setTitle:@" 至少填写一份症状描述" forState:UIControlStateNormal];
        [tipBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        tipBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.bottomView addSubview:tipBtn];
        tipBtn.hidden = YES;
        
        [tipBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bottomView);
            make.right.equalTo(self.bottomView).offset(-10);
        }];
    }
    return self;
}

-(UIView *)topView
{
    if (_topView == nil)
    {
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = GlobalBgColor;
        [self.contentView addSubview:_topView];
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(44);
        }];
    }
    return _topView;
}

-(UIView *)bottomView
{
    if (_bottomView == nil)
    {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_bottomView];
        
        [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(self.topView.mas_bottom);
            make.height.mas_equalTo(44);
        }];
    }
    return _bottomView;
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        //treatmentProcess
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"symptomsDescribed"]];
        [self.topView addSubview:_iconView];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.topView);
            make.left.equalTo(self.topView).offset(10);
        }];
    }
    return _iconView;
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = GLobalFontColor;
        _titleLabel.text = @"症状描述";
        [self.topView addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(10);
            make.centerY.equalTo(self.topView);
        }];
    }
    return _titleLabel;
}

-(UIImageView *)lineImageView
{
    if (_lineImageView == nil)
    {
        _lineImageView = [[UIImageView alloc] init];
        _lineImageView.backgroundColor = GlobalColor;
        [self.bottomView addSubview:_lineImageView];
        
        [_lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomView).offset(10);
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(24);
            make.centerY.equalTo(self.bottomView);
        }];
    }
    return _lineImageView;
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil)
    {
        _timeLabel = [UILabel new];
        _timeLabel.font = [UIFont systemFontOfSize:15];
        _timeLabel.textColor = GLobalFontColor;
        [self.bottomView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomView).offset(10);
            make.centerY.equalTo(self.bottomView);
        }];
    }
    return _timeLabel;
}

-(void)setIsFooter:(BOOL)isFooter
{
    _isFooter = isFooter;
    
    if (isFooter)
    {
        self.iconView.image = [UIImage imageNamed:@"treatmentProcess"];
        self.titleLabel.text = @"治疗过程";
        
        self.lineImageView.hidden = NO;
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomView).offset(22);
        }];
    }
    else
    {
        self.iconView.image = [UIImage imageNamed:@"symptomsDescribed"];
        self.titleLabel.text = @"症状描述";
        
        self.lineImageView.hidden = YES;
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomView).offset(10);
        }];
    }
}

-(void)setTime:(NSString *)time
{
    _time = time;
    
    self.timeLabel.text = time;
}

-(void)setIsChargeExample:(BOOL)isChargeExample
{
    _isChargeExample = isChargeExample;
    
    if (isChargeExample)
    {
        self.tipBtn.hidden = NO;
        
        if (self.isFooter)
        {
            [self.tipBtn setTitle:@" 至少填写一份治疗过程" forState:UIControlStateNormal];
        }
    }
}

@end
